<?php

namespace App\Services;

use App\Exceptions\BusinessException;
use App\Helpers\CodeResponse;

class BaseService {
    private static $instance;

    private function __construct() {
    }

    /**
     * @return static
     * @author LL
     */
    public static function getInstance() {
        if (static::$instance instanceof static) {
            return static::$instance;
        }
        static::$instance = new static();
        return static::$instance;
    }

    protected function updateFail(bool $ok, $info = null) {
        if (!$ok) {
            throw new BusinessException(CodeResponse::UPDATE_FAIL, $info);
        }
    }

    protected function deleteFail(bool $ok, $info = null) {
        if (!$ok) {
            throw new BusinessException(CodeResponse::UPDATE_FAIL, $info);
        }
    }

    protected function isNotNullModel($model,$info=null){
        if (!$model){
            throw new BusinessException(CodeResponse::PARAM_FAIL,$info??'模型数据不存在');
        }
    }
    private function __clone() {
        // TODO: Implement __clone() method.
    }

    protected function paramFail(){
        throw new BusinessException(CodeResponse::PARAM_FAIL);
    }
}
